package com.design.twords.adatper;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.design.twords.R;
import com.design.twords.entity.ItemHelpTips;

import java.util.ArrayList;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Create by Alen
 * Time:  2:05
 */
public class HelpsAdapter extends RecyclerView.Adapter<HelpsAdapter.MyViewHolder>{

    private LayoutInflater myInflater;
    private ArrayList<ItemHelpTips> helpTips;
    private Context context;
    private int viewId;

    public HelpsAdapter(ArrayList<ItemHelpTips> helpTips, Context context, int viewId) {
        this.myInflater = LayoutInflater.from(context);
        this.helpTips = helpTips;
        this.context = context;
        this.viewId = viewId;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyViewHolder(myInflater.inflate(viewId, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        ItemHelpTips item = helpTips.get(position);
        holder.question.setText(item.getQuestion());
        holder.answer.setText(item.getAnswer());
    }

    @Override
    public int getItemCount() {
        return helpTips.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView question, answer;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            question = itemView.findViewById(R.id.helptips_question);
            answer = itemView.findViewById(R.id.helptips_answer);

        }
    }
}
